<?php

namespace Cck\ArticlesSystem\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class RoleUpdateRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {

        $id = $this->route('role')->id;

        return [
            'display_name' => [
                'required',
                'max:30',
                Rule::unique('roles', 'display_name')->ignore($id)
            ],
            'description' => 'max:255',
            'permissions' => 'array',
            'permissions.*' => [
                'required',
                'integer',
                'distinct',
                Rule::exists('permissions', 'id')
            ]
        ];
    }
}
